package com.xh.bussiness.exam.service.impl;

import com.xh.bussiness.exam.bean.dto.StudentPaperQuestionDifficultDto;
import com.xh.bussiness.exam.bean.request.StudentPaperAnswerDetailRequest;
import com.xh.bussiness.exam.model.StudentPaperAnswerDetail;
import com.xh.bussiness.exam.dao.StudentPaperAnswerDetailMapper;
import com.xh.bussiness.exam.service.IStudentPaperAnswerDetailService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;
import java.util.List;
/**
 * <p>
 * 作业发布-学生任务-作答明细 服务实现类
 * </p>
 *
 * @author Pitt Cheung
 * @since 2021-07-28
 */
@Service
public class StudentPaperAnswerDetailServiceImpl extends BaseServiceImpl<StudentPaperAnswerDetailMapper, StudentPaperAnswerDetail> implements IStudentPaperAnswerDetailService {
    @Override
    public XhPage queryStudentPaperAnswerDetailPage(XhPage page, StudentPaperAnswerDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<StudentPaperAnswerDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryStudentPaperAnswerDetail(StudentPaperAnswerDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<StudentPaperAnswerDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public List<StudentPaperAnswerDetail> queryByAnswerId(String answerId) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("student_paper_answer_id", answerId);
        return this.dao.selectList(qw);
    }

    @Override
    public void deleteByAnswerIdId(String answerId) {
        this.dao.deleteByAnswerIdId(answerId);
    }

    @Override
    public List<StudentPaperQuestionDifficultDto> queryStudentPaperQuestionDifficult(String answerId) {
        return this.dao.queryStudentPaperQuestionDifficult(answerId);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(StudentPaperAnswerDetailRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
